package com.ypx;

import java.util.HashSet;
import java.util.Iterator;
import java.util.function.Consumer;

public class HashSetDemo {
    public static void main(String[] args) {
        // 创建HashSet对象
        HashSet<String> hashSet = new HashSet<>();
        //保存数据
        hashSet.add("尤柯");
        hashSet.add("赵鑫");
        hashSet.add("张植");
        hashSet.add("喻浦熊");
        System.out.println(hashSet);



        //取数据（使用迭代器）
        Iterator<String> iterator = hashSet.iterator();
        while (iterator.hasNext()) {
            String next = iterator.next();
            System.out.println(next);
        }
        //for循环用不了

        //增强for循环
        for (String str : hashSet) {
            System.out.println(str);
        }

        int[] arr = {1, 2, 3, 4, 5,6,7,8,9,10};
        for (int i : arr) {     //?
            System.out.println(i);
        }


        //取数据lambda表达式
        hashSet.forEach(new Consumer<String>() {
           @Override
           public void accept(String s){
                System.out.println(s);
           }
        });


        hashSet.forEach(s -> System.out.println(s));
        hashSet.forEach(System.out::println);


    }
}
